package com.bookworms.helloandengine.game.ui;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.scene.menu.item.IMenuItem;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.entity.util.FPSLogger;
import org.anddev.andengine.ui.activity.BaseGameActivity;
import test.test.R;

import javax.microedition.khronos.opengles.GL10;

/**
 * Кто запилил: EVSafronov
 * Когда запилил: 21.05.12
 * Во сколько запилил: 17:58
 */
public class BaseScreen extends BaseGameActivity {
    protected Camera mCamera;
    protected int mCameraHeight;
    protected int mCameraWidth;

    @Override
    public Engine onLoadEngine() {
        mCameraWidth = getWindowManager().getDefaultDisplay().getWidth();
        mCameraHeight = getWindowManager().getDefaultDisplay().getHeight();
        mCamera = new Camera(0, 0, mCameraWidth, mCameraHeight);
        RatioResolutionPolicy resolutionPolicy = new RatioResolutionPolicy(mCameraWidth, mCameraHeight);
        return new Engine(new EngineOptions(true, EngineOptions.ScreenOrientation.LANDSCAPE, resolutionPolicy, mCamera));
    }

    @Override
    public void onLoadResources() {
    }

    @Override
    public Scene onLoadScene() {
        mEngine.registerUpdateHandler(new FPSLogger());
        return new Scene();
    }

    @Override
    public void onLoadComplete() {
    }

    @Override
    protected void onPause() {
        super.onPause();
        overridePendingTransition(R.anim.fadein, R.anim.fadeout);
    }

    protected void setFadeOutBlend(Sprite sprite) {
        sprite.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
    }

    protected void setFadeOutBlend(IMenuItem sprite) {
        sprite.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
    }
}
